
function bigNumberSun(bigNumberA,bigNumberB){
    // 1. 把两个大整数用数组逆序存储，数组长度等于较大整数位+1

    bigNumberA=bigNumberA.split("").map(item=>parseInt(item))
    bigNumberB=bigNumberB.split("").map(item=>parseInt(item))
    //console.log(bigNumberA,bigNumberB)
    let maxLength = bigNumberA.length>bigNumberB.length?bigNumberA.length:bigNumberB.length;
    let arrayA = new Array(maxLength+1);
    let arrayB = new Array(maxLength+1);
    let result = new Array(maxLength+1);
    //console.log(arrayA,arrayB,result)
    for(let i=0;i<maxLength+1;i++){
        if (i<bigNumberA.length){
            arrayA[i]=bigNumberA[bigNumberA.length-1-i]
        }else{
            arrayA[i]=0;
        }

        if (i<bigNumberB.length){
            arrayB[i]=bigNumberB[bigNumberB.length-1-i]
        }else{
            arrayB[i]=0;
        }
        result[i]=0;
    
    }
    //console.log(arrayA,arrayB,result)
    //2. 遍历数组A B  每位相加
    for(let i=0;i<maxLength+1;i++){
        let sum= arrayA[i]+arrayB[i]+result[i];
        //console.log(sum);
        if(sum >= 10){
            sum=sum-10;
            result[i+1]=1;
        }
        result[i]=sum;
    }
    //console.log(arrayA,arrayB,result)
    // 把 result 逆序输出 去掉高位的0

    // 是否找到大整数的最高位
    let findFirst = false;
    let res=""
    for(let i=result.length-1;i>=0;i--){
        if(!findFirst){
            if(result[i]==0){
                continue
            }
            findFirst=true;
        }
        res+=result[i];
    }
    return res;
}
console.log(bigNumberSun("123","4567"))

 